#include "LifeBoard.h"

LifeBoard::LifeBoard(int xLength, int yLength)
{
    //creates the first row of the array with int pointers
    gameBoard = new int*[xRange];

    //inserts an int array into each cell of the first row of the pointer
    for(int i = 0; i < xRange; i++){
      gameBoard[i] = new int[yRange];
    }

    xRange = xLength;
    yRange = yLength;
}

LifeBoard::~LifeBoard()
{
    //deletes all of the dynamically created arrays in the first row of gameBoard
    for(int i = 0; i < this->getLifeBoardXRange(); i++){
      delete [] gameBoard[i];
    }

    //deletes the dynamically created first row removing the double pointer
    delete [] gameBoard;
}

void LifeBoard::setLifeBoard(bool alive, int xValue, int yValue){
    if(alive)
        gameBoard[xValue][yValue] = 1;
    else
        gameBoard[xValue][yValue] = 0;
}

int LifeBoard::getLifeBoardXRange(){
  return xRange;
}

int LifeBoard::getLifeBoardYRange(){
  return yRange;
}

int LifeBoard::getLifeBoardValue(int xValue, int yValue){
  return gameBoard[xValue][yValue];
}
